﻿using System;
using System.Collections.Generic;
using ZwSoft.ZwCAD.Colors;
using ZwSoft.ZwCAD.DatabaseServices;
using ZwSoft.ZwCAD.Geometry;
using static System.Net.Mime.MediaTypeNames;

namespace DX_Recognize.Entitys
{
    //线段类型
    public enum CADLineType
    {
        //未判定
        NONE,
        //X方向直线(横)
        XDirLine,
        //Y方向直线(竖)
        YDirLine,
        //斜线
        ObliqueLine
    }

    //两线段相连类型
    public enum LineJoinType
    {
       //不相连
        None,
        //线段1起点连接线段2起点
        FSJoinSS,
        //线段1起点连接线段2终点
        FSJoinSE,
        //线段1终点连接线段2起点
        FEJoinSS,
        //线段1终点连接线段2终点
        FEJoinSE,
    }

    //CAD 圆数据
    public class CAD_Circle
    {
        public ObjectId CAD_ObjectId { get; set; }
        public Boolean IsBlockEleFlag { get; set; } = false;
        public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();
        //圆点坐标
        public CAD_Point CenterPoint { get; set; } = new CAD_Point();
        //直径
        public double Diameter { get; set; }

        public static bool operator == (CAD_Circle circle1, CAD_Circle circle2)
        {
            if (ReferenceEquals(circle1, null) && ReferenceEquals(circle2, null))
                return true;
            if (ReferenceEquals(circle1, null) || ReferenceEquals(circle2, null))
                return false;
            Boolean F1 = Math.Round(circle1.CenterPoint.X, 3) == Math.Round(circle2.CenterPoint.X, 3);
            Boolean F2 = Math.Round(circle1.CenterPoint.Y, 3) == Math.Round(circle2.CenterPoint.Y, 3);
            Boolean F3 = circle1.Diameter == circle2.Diameter;
            return F1 && F2 && F3;
        }

        // 重载 != 运算符
        public static bool operator !=(CAD_Circle circle1, CAD_Circle circle2)
        {
            // 使用已经定义的 == 运算符
            return !(circle1 == circle2);
        }

        // Equals 方法用于配合重载的 == 运算符
        public override bool Equals(object obj)
        {
            if (obj is CAD_Circle other)
                return this == other;
            return false;
        }

    }

    //CAD 线段数据
    public class CAD_Line
    {
        // public ObjectId CAD_ObjectId { get; set; }
        //这里考虑组装图EGP是用块去生成的
        public Boolean IsBlockEleFlag { get; set; } = false;
        //public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();
        //起始点
        public CAD_Point StartPoint { get; set; } = new CAD_Point();
        //终点
        public CAD_Point EndPoint { get; set; } = new CAD_Point();
        //线段长度
        public double Length { get; set; }
        //线段类型
        public CADLineType LineType { get; set; } = CADLineType.NONE;
        //起点是否挂有倒角
        public Boolean SPChamferFlag { get; set; } = false;
        //终点是否挂有倒角
        public Boolean EPChamferFlag { get; set; } = false;
        //起点关联的倒角线段
        public CAD_Line SCLine { get; set; }
        //终点关联的倒角线段
        public CAD_Line ECLine { get; set; }
        public CAD_Color ColorInfo { get; set; } = new CAD_Color();
        //图层名称
        public string LayerName { get; set; } = "";
    }

    //CAD 线段数据
    public class MixedCAD_Line
    {
        //这里考虑组装图EGP是用块去生成的
        public Boolean IsBlockEleFlag { get; set; } = false;
        //public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();
        //起始点
        public MixedCAD_Point StartPoint { get; set; } = new MixedCAD_Point();
        //终点
        public MixedCAD_Point EndPoint { get; set; } = new MixedCAD_Point();
        //线段长度
        public double Length { get; set; }
        //线段类型
        public CADLineType LineType { get; set; } = CADLineType.NONE;
        //起点是否挂有倒角
        public Boolean SPChamferFlag { get; set; } = false;
        //终点是否挂有倒角
        public Boolean EPChamferFlag { get; set; } = false;
        //起点关联的倒角线段
        public MixedCAD_Line SCLine { get; set; }
        //终点关联的倒角线段
        public MixedCAD_Line ECLine { get; set; }
        public CAD_Color ColorInfo { get; set; } = new CAD_Color();
        //图层名称
        public string LayerName { get; set; } = "";
        //所在板
        List<string> InBoardList = new List<string>();
    }

    //CAD 颜色属性
    public class CAD_Color
    {
        //名称颜色展示
        public String ColorNameForDisplay { get; set; }
        //颜色序号
        public string ColorIndex { get; set; } = "";
    }

    // 自定义比较器类
    public class MixedCADLineEQComparer : IEqualityComparer<MixedCAD_Line>
    {
        public bool Equals(MixedCAD_Line line1, MixedCAD_Line line2)
        {
            Boolean F5 = line1.LayerName.Equals(line2.LayerName);
            Boolean F1 = line1.StartPoint.CustomerPoint.X == line2.StartPoint.CustomerPoint.X;
            Boolean F2 = line1.StartPoint.CustomerPoint.Y == line2.StartPoint.CustomerPoint.Y;
            Boolean F3 = line1.EndPoint.CustomerPoint.X == line2.EndPoint.CustomerPoint.X;
            Boolean F4 = line1.EndPoint.CustomerPoint.Y == line2.EndPoint.CustomerPoint.Y;
            return F1 && F2 && F3 && F4 && F5;
        }
        public int GetHashCode(MixedCAD_Line obj)
        {
            return obj.StartPoint.GetHashCode() + obj.EndPoint.GetHashCode();
        }
    }

    //CAD Point3d只支持可读 
    [Serializable]
    public class CAD_Point
    {
        public CAD_Point()
        {
 
        }
        public CAD_Point(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public static bool operator == (CAD_Point Point1, CAD_Point Point2)
        {
            Boolean F1 = Point1.X == Point2.X;
            Boolean F2 = Point1.Y == Point2.Y;
            if (F1 && F2)
                return true;
            return false;
        }

        public static bool operator != (CAD_Point Point1, CAD_Point Point2)
        {
            return !(Point1 == Point2);
        }
    }
   
    //CAD 圆弧
    public class CAD_Arc
    {
        public ObjectId CAD_ObjectId { get; set; }
        //这里考虑组装图EGP是用块去生成的
        public Boolean IsBlockEleFlag { get; set; } = false;
       /* public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();*/
        public CAD_Point StartPoint { get; set; } = new CAD_Point();
        public CAD_Point EndPoint { get; set; } = new CAD_Point();
        public double Length { get; set; }
        public double Radius { get; set; }
        public CAD_Point CenterPoint { get; set; } = new CAD_Point();
        //圆弧的圆心角
        public double Angle { get; set; }
        //圆弧朝向
        public AngleDir Dir { get; set; } = AngleDir.NONE;
    }

    public class MixedCAD_Arc
    {
        public ObjectId CAD_ObjectId { get; set; }
        //这里考虑组装图EGP是用块去生成的
        public Boolean IsBlockEleFlag { get; set; } = false;
        /* public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();*/
        public MixedCAD_Point StartPoint { get; set; } = new MixedCAD_Point();
        public MixedCAD_Point EndPoint { get; set; } = new MixedCAD_Point();
        public double Length { get; set; }
        public double Radius { get; set; }
        public MixedCAD_Point CenterPoint { get; set; } = new MixedCAD_Point();
        //圆弧的圆心角
        public double Angle { get; set; }
        //圆弧朝向
        public AngleDir Dir { get; set; } = AngleDir.NONE;
    }

    //CAD 曲线
    public class CAD_Curve
    {
        public ObjectId CAD_ObjectId { get; set; }
        //最左
        public CAD_Point MinXPoint { get; set; } = new CAD_Point();
        //最右
        public CAD_Point MaxXPoint { get; set; } = new CAD_Point();
        //最高点
        public CAD_Point MaxYPoint { get; set; } = new CAD_Point();
        //最低点
        public CAD_Point MinYPoint { get; set; } = new CAD_Point();
    }

    public class MixedCAD_Curve
    {
        //最左
        public MixedCAD_Point MinXPoint { get; set; } = new MixedCAD_Point();
        //最右
        public MixedCAD_Point MaxXPoint { get; set; } = new MixedCAD_Point();
        //最高点
        public MixedCAD_Point MaxYPoint { get; set; } = new MixedCAD_Point();
        //最低点
        public MixedCAD_Point MinYPoint { get; set; } = new MixedCAD_Point();
    }

    //CAD 文字
    public class CAD_Text
    {
        //CAD_id
        public ObjectId CAD_ObjectId { get; set; }
        public Boolean IsBlockEleFlag { get; set; } = false;
        // 获取文字大小
        //public double HeightSize { get; set; }
        //if 块  块的参考坐标
        public CAD_Point BlockRefPosition { get; set; } = new CAD_Point();
        public CAD_Point PositionPoint { get; set; } = new CAD_Point();
        public string Centent { get; set; }
    }

    public class MixedCAD_Text
    {
        //CAD_id
        public ObjectId CAD_ObjectId { get; set; }
        public Boolean IsBlockEleFlag { get; set; } = false;
        // 获取文字大小
        //public double HeightSize { get; set; }
        //if 块  块的参考坐标
        public MixedCAD_Point BlockRefPosition { get; set; } = new MixedCAD_Point();
        public MixedCAD_Point PositionPoint { get; set; } = new MixedCAD_Point();
        public string Centent { get; set; }
    }

    //CAD 客图关注的标注内容(这里指板区域标注)
    public class CAD_Dimension
    {
        //标注的长度
        public double DimensionLength { get; set; }
        //X坐标
        public double? X { get; set; } = null;
        //最高点Y坐标
        public double? HighY  {get; set; } = null;
        //最底点Y坐标
        public double? LowY { get; set; } = null;
        //属于哪块板 用于后面匹配
        public String BoardUID { get; set; } = null;

    }

    // 自定义  圆 复合键类
    public class CircleKey
    {
        public double CircleX { get; set; }
        public double CircleY { get; set; }

        // 实现 Equals 和 GetHashCode 方法，以确保字典能够正确比较和存储复合键
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is CircleKey))
                return false;
            CircleKey other = (CircleKey)obj;
            Boolean F1 = Math.Round(this.CircleX, 2) == Math.Round(other.CircleX, 2);
            Boolean F2 = Math.Round(this.CircleY, 2) == Math.Round(other.CircleY, 2);
            return F1 && F2;
        }

        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + CircleX.GetHashCode();
            hash = hash * 23 + CircleY.GetHashCode();
            return hash;
        }
    }



}
